//
//  MPTabbar.swift
//  MPSinaWeibo
//
//  Created by DaVinci on 16/4/6.
//  Copyright © 2016年 DaVinci. All rights reserved.
//

import UIKit

class MPTabbar: UITabBar {
    
    
    override init(frame: CGRect) {
        
        super.init(frame: frame)
        
        addSubview(plusBtn)
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func layoutSubviews() {
        super.layoutSubviews()
        
        var index: CGFloat = 0
        let width = UIScreen.mainScreen().bounds.width / 5
        let height = self.bounds.height
        let rect = CGRect(x: 0, y: 0, width: width, height: height)
        
        
        
        for subview in subviews {
        
            if subview.isKindOfClass(NSClassFromString("UITabBarButton")!){
            
                subview.frame = CGRectOffset(rect, index * width, 0)
            
                index += (index==1) ? 2 : 1
                
                
                plusBtn.frame = CGRectMake(2 * width, 0, width, height)
                
            }
            
        }
    }
    
    
     lazy var plusBtn: UIButton = {
    
        let button = UIButton()
        
        button.setBackgroundImage(UIImage(named: "tabbar_compose_button"), forState: .Normal)
        button.setBackgroundImage(UIImage(named: "tabbar_compose_button_highlighted"), forState: .Highlighted)
        
        button.setImage(UIImage(named: "tabbar_compose_icon_add"), forState: .Normal)
        button.setImage(UIImage(named: "tabbar_compose_icon_add_highlighted"), forState: .Highlighted)
        
        return button
    
    }()
}
